package com.niit.service.impl;

import com.niit.dao.INewsDao;
import com.niit.dao.IProductDao;
import com.niit.dao.impl.NewsDaoImpl;
import com.niit.dao.impl.ProductDaoImpl;
import com.niit.domain.News;
import com.niit.domain.Product;
import com.niit.service.INewsService;
import domain.PageBean;

import java.util.List;

public class NewsServiceImpl implements INewsService {
    @Override
    public List<News> newsService(Integer pageSize) {
        INewsDao iNewsDao=new NewsDaoImpl();
        List<News> list=iNewsDao.queryNews(pageSize);
        return list;
    }

    @Override
    public List<News> newsService2(Integer pageSize) {
        INewsDao iNewsDao2=new NewsDaoImpl();
        List<News> list=iNewsDao2.queryNews2(pageSize);
        return list;
    }

    @Override
    public List<News> newsService3(Integer pageSize) {
        INewsDao iNewsDao3=new NewsDaoImpl();
        List<News> list=iNewsDao3.queryNews3(pageSize);
        return list;
    }

    @Override
    public PageBean<News> queryProductsService(Integer currentPage, Integer pageSize) {
        INewsDao iNewsDao = new NewsDaoImpl();
        domain.PageBean<News> pageBean =new PageBean<News>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);

        int Count = iNewsDao.queryNewsTotal();
        pageBean.setTotalCount(Count);

        int totalPage = Count % pageSize == 0 ? Count / pageSize :(Count / pageSize) + 1 ;
        pageBean.setTotalPage(totalPage);

        currentPage=(currentPage-1)*pageSize;
        pageBean.setList(iNewsDao.queryAllNews(currentPage,pageSize));
        return pageBean;
    }

    @Override
    public News queryNewsByIDService(Integer id) {
        INewsDao iNewsDao = new NewsDaoImpl();
        News news = iNewsDao.queryNewsByID(id);
        return news;
    }

    @Override
    public int newsClickNum(Integer id) {
        INewsDao iNewsDao = new NewsDaoImpl();
        int i = iNewsDao.NewsCountadd(id);
        return i;
    }
}
